{smcl}
{com}{sf}{ul off}{txt}{.-}
      name:  {res}<unnamed>
       {txt}log:  {res}C:\Users\myogo\Princeton Dropbox\Motohiro Yogo\Koijen Yogo - International\JPE\Replication\Code\1 Data\WorldBank.smcl
  {txt}log type:  {res}smcl
 {txt}opened on:  {res}31 Oct 2025, 09:17:09
{txt}
{com}. /* Define local and global variables */
> 
> local directory = "../../Data/World Bank";
{txt}
{com}. do global;
{txt}
{com}. /* global.do (STATA)
>         Define global variables in "Data".
>         by Ralph Koijen & Motohiro Yogo */
. 
. #delimit ;
{txt}delimiter now ;
{com}. clear all;
{res}{txt}
{com}. global year_min = 2003;
{txt}
{com}. global year_max = 2020;
{txt}
{com}. global small = 5e-4;
{txt}
{com}.         /* Minimum reportable threshold for CPIS */

{txt}end of do-file

{com}. /* Loop through files */
> 
> tempfile WorldBank;
{txt}
{com}. qui foreach file in "API_CM.MKT.LCAP.CD_DS2_en_excel_v2_5608355"
>         "API_FP.CPI.TOTL_DS2_en_excel_v2_5607584"
>         "API_NE.CON.TOTL.CD_DS2_en_excel_v2_5611059"
>         "API_NE.CON.TOTL.KN_DS2_en_excel_v2_5611597"
>         "API_NY.GDP.MKTP.CD_DS2_en_excel_v2_5607200"
>         "API_NY.GDP.MKTP.KN_DS2_en_excel_v2_5607598"
>         "API_NY.GDP.MKTP.PP.CD_DS2_en_excel_v2_5795834"
>         "API_NY.GDP.PCAP.PP.CD_DS2_en_excel_v2_5708311"
>         "API_PA.NUS.PPP_DS2_en_excel_v2_5607721"
>         "API_PA.NUS.PRVT.PP_DS2_en_excel_v2_5607340"
>         "API_SP.POP.TOTL_DS2_en_excel_v2_5607126"{c -(};
{txt}
{com}. /* Rename variables */
> 
> rename CountryCode country;
{res}{txt}
{com}. local i = 1960;
{txt}
{com}. foreach var of varlist E-Z A* B* {c -(};
{txt}  2{com}.         rename `var' _`i';
{txt}  3{com}.         local i = `i'+1;
{txt}  4{com}. {c )-};
{res}{txt}
{com}. /* Fix variables */
> 
> replace IndicatorCode = subinstr(IndicatorCode,".","",.);
{txt}(2,926 real changes made)

{com}. /* Reshape in long format */
> 
> reshape long _, i(country IndicatorCode) j(year);
{txt}(j = 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022)

Data{col 36}Wide{col 43}->{col 48}Long
{hline 77}
Number of observations     {res}       2,926   {txt}->   {res}184,338     
{txt}Number of variables        {res}          65   {txt}->   {res}4           
{txt}j variable (63 values)                    ->   {res}year
{txt}xij variables:
                  {res}_1960 _1961 ... _2022   {txt}->   {res}_
{txt}{hline 77}

{com}. reshape wide _, i(year country) j(IndicatorCode) string;
{txt}(j = CMMKTLCAPCD FPCPITOTL NECONTOTLCD NECONTOTLKN NYGDPMKTPCD NYGDPMKTPKN NYGDPMKTPPPCD NYGDPPCAPPPCD PANUSPPP PANUSPRVTPP SPPOPTOTL)

Data{col 36}Long{col 43}->{col 48}Wide
{hline 77}
Number of observations     {res}     184,338   {txt}->   {res}16,758      
{txt}Number of variables        {res}           4   {txt}->   {res}13          
{txt}j variable (11 values)    {res}IndicatorCode   {txt}->   (dropped)
xij variables:
                                      {res}_   {txt}->   {res}_CMMKTLCAPCD _FPCPITOTL ... _SPPOPTOTL
{txt}{hline 77}

{com}. /* Rename variables */
> 
> foreach var in CMMKTLCAPCD FPCPITOTL NECONTOT* NYGDP* PANUS* SPPOPTOTL {c -(};
{txt}  2{com}.         rename _`var' `var';
{txt}  3{com}. {c )-};
{res}{txt}
{com}. rename CMMKTLCAPCD outstand;
{res}{txt}
{com}. rename FPCPITOTL cpi;
{res}{txt}
{com}. rename NECONTOTLCD cons;
{res}{txt}
{com}. rename NECONTOTLKN consR;
{res}{txt}
{com}. rename NYGDPMKTPCD gdp;
{res}{txt}
{com}. rename NYGDPMKTPKN gdpR;
{res}{txt}
{com}. rename NYGDPMKTPPPCD gdpP;
{res}{txt}
{com}. rename NYGDPPCAPPPCD gdpPpc;
{res}{txt}
{com}. rename SPPOPTOTL pop;
{res}{txt}
{com}. /* Convert to billion */
> 
> foreach var of varlist outstand cons consR gdp gdpR gdpP pop {c -(};
{txt}  2{com}.         replace `var' = `var'/1e9;
{txt}  3{com}. {c )-};
{txt}(3,244 real changes made)
(10,702 real changes made)
(6,914 real changes made)
(13,366 real changes made)
(10,281 real changes made)
(7,704 real changes made)
(16,665 real changes made)

{com}. /* Convert PPP conversion factor to US$ per LCU */
> 
> foreach var of varlist PANUS* {c -(};
{txt}  2{com}.         replace `var' = 1/`var';
{txt}  3{com}. {c )-};
{txt}(6,168 real changes made)
(5,605 real changes made)

{com}. /* Sample criteria */
> 
> keep if inrange(year,$year_min-1,$year_max+1);
{txt}(11,438 observations deleted)

{com}. /* Label variables */
> 
> order year country;
{txt}
{com}. label var year                  "Year";
{txt}
{com}. label var country               "Investor country";
{txt}
{com}. label var outstand              "Market capitalization of listed domestic companies (US$ billion)";
{txt}
{com}. label var cpi                   "Consumer price index";
{txt}
{com}. label var cons                  "Consumption, Nominal (US$ billion)";
{txt}
{com}. label var consR                 "Consumption, Real (LCU billion)";
{txt}
{com}. label var gdp                   "GDP, Nominal (US$ billion)";
{txt}
{com}. label var gdpR                  "GDP, Real (LCU billion)";
{txt}
{com}. label var gdpP                  "GDP, Nominal PPP (US$)";
{txt}
{com}. label var gdpPpc                "GDP per capita, Nominal PPP (US$)";
{txt}
{com}. label var PANUSPPP              "PPP conversion factor, GDP (US$ per LCU)";
{txt}
{com}. label var PANUSPRVTPP   "PPP conversion factor, Consumption (US$ per LCU)";
{txt}
{com}. label var pop                   "Population (billion)";
{txt}
{com}. /* Save data */
> 
> sort year country;
{txt}
{com}. save WorldBank, replace;
{txt}{p 0 4 2}
file {bf}
WorldBank.dta{rm}
saved
{p_end}

{com}. log close;
      {txt}name:  {res}<unnamed>
       {txt}log:  {res}C:\Users\myogo\Princeton Dropbox\Motohiro Yogo\Koijen Yogo - International\JPE\Replication\Code\1 Data\WorldBank.smcl
  {txt}log type:  {res}smcl
 {txt}closed on:  {res}31 Oct 2025, 09:17:13
{txt}{.-}
{smcl}
{txt}{sf}{ul off}